package com.xjgc.eip.panel.controller;


import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jeecg.common.api.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xjgc.common.utils.DateUtil;
import com.xjgc.eip.panel.entity.ZxjEipXsdd;
import com.xjgc.eip.panel.service.ZxjEipXsddService;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wxy
 * @since 2019-11-08
 */
@RestController
@RequestMapping("/zxjEipXsdd")
public class ZxjEipXsddController {
    @Autowired
    private ZxjEipXsddService zxjEipXsddService;
    @RequestMapping("salesOrder")
    public Result<IPage<ZxjEipXsdd>> salesOrder(ZxjEipXsdd zxjEipXsdd, @RequestParam(name = "pageNo",defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize",defaultValue = "10") Integer pageSize){
        Result<IPage<ZxjEipXsdd>> result=new Result<>();
        Page<ZxjEipXsdd> page = new Page<ZxjEipXsdd>(pageNo,pageSize);
        QueryWrapper<ZxjEipXsdd> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(zxjEipXsdd);
        IPage<ZxjEipXsdd> pageList = zxjEipXsddService.page(page,queryWrapper);
        result.setSuccess(true);
        result.setResult(pageList);
        return result;
    }
    @RequestMapping("getOrderCount")
    public Map getOrderCount() throws ParseException {
        //今天推送数量
        Map paramMap=new HashMap();
        paramMap.put("pushTime",DateUtil.today());
        Map totalMap=zxjEipXsddService.selectByTime(paramMap);
        paramMap.put("supplierCode","1000018466");
        Map baozhiMap=zxjEipXsddService.selectByTime(paramMap);
        Map statistics=new HashMap();
        statistics.put("total",totalMap.get("salescount"));
        statistics.put("erci",baozhiMap.get("salescount"));
        int total=Integer.parseInt(totalMap.get("salescount").toString());
        int erci=Integer.parseInt(baozhiMap.get("salescount").toString());
        statistics.put("yibiao",total-erci);
        //昨天推送数量
        Map yParamMap=new HashMap();
        yParamMap.put("date",DateUtil.yestoday());
        Map yTotalMap=zxjEipXsddService.selectByTime(yParamMap);
        yParamMap.put("supplierCode","1000018466");
        Map yBaozhiMap=zxjEipXsddService.selectByTime(yParamMap);
        int yTotal=Integer.parseInt(yTotalMap.get("salescount").toString());
        int yErci=Integer.parseInt(yBaozhiMap.get("salescount").toString());
        if (yTotal !=0) {
            statistics.put("compareTotal",(total-yTotal)/yTotal);
            statistics.put("compareErci",(erci-yErci)/yTotal);
            statistics.put("compareYb",((total-erci)-(yTotal-yErci))/(yTotal-yErci));
        }else if(total!=0){
            statistics.put("compareTotal","100%");
            statistics.put("compareErci","100%");
            statistics.put("compareYb","100%");
        }
        return statistics;
    }
    @RequestMapping("selectByAreaTime")
    public Map selectByAreaTime() throws ParseException {
        return zxjEipXsddService.selectByAreaTime();
    }
    @RequestMapping("selectByMonth")
    public Map selectByMonth() throws ParseException {
        return zxjEipXsddService.selectByMonth();
    }
    @RequestMapping("selectByJidu")
    public List<Map> selectByJidu(){
        return zxjEipXsddService.selectByJiDu();
    }
    @RequestMapping("selectByYear")
    public Map selectByYear(){
        return zxjEipXsddService.selectByYear();
    }
}

